<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>getElementsByTagName获取checkbox进行全选</title>
		<style type="text/css">
			#myTable{ width: 900px; margin: 0px auto; background-color: #008000;}
			#myTable td,#myTable th{ background-color: white;}
			#myDiv{width: 900px; margin: 0px auto; height: 30px; line-height: 30px; 
			text-align: center;}
		</style>
		<!-- <script>======代码======</script> -->
	</head>
	<body>
		<table cellspacing="1" id="myTable">
			<tr>
				<th width="200">
                  <input type="checkbox" id="selAll1" onchange="fu1()" />全选
				<input type="checkbox" id="selAll2" onchange="fn2" />反选
                        </th>
				<th width="200">姓名</th>
				<th width="200">性别</th>
				<th width="200">专业</th>
				<th width="200">爱好</th>
			</tr>
			<tr>
				<td><input type="checkbox" id="b1" class="box" onchange="fu12()"/></td>
				<td>刘备</td>
				<td>男</td>
				<td>软件开发</td>
				<td>抽烟</td>
			</tr>
			<tr>
				<td><input type="checkbox" id="b2" class="box" onchange="fu12()"/></td>
				<td>关羽</td>
				<td>男</td>
				<td>国际贸易</td>
				<td>喝酒</td>
			</tr>
			<tr>
				<td><input type="checkbox" id="b3" class="box" onchange="fu12()"/></td>
				<td>张飞</td>
				<td>男</td>
				<td>园林设计</td>
				<td>烫头发</td>
			</tr>
			<tr>
				<td><input type="checkbox" id="b4" class="box" onchange="fu12()"/></td>
				<td>赵云</td>
				<td>男</td>
				<td>平面设计</td>
				<td>抽烟</td>
			</tr>
			<tr>
				<td><input type="checkbox" id="b5" class="box" onchange="fu12()"/></td>
				<td>黄忠</td>
				<td>男</td>
				<td>影视制作</td>
				<td>玩游戏</td>
			</tr>
			<tr>
				<td><input type="checkbox" id="b6" class="box" onchange="fu12()"/></td>
				<td>小乔</td>
				<td>女</td>
				<td>高级护理</td>
				<td>唱歌</td>
			</tr>
		</table>
		<script>
			var pd1=document.getElementById('selAll1')
			console.log(pd1.checked);
			function fu1(){
				console.log(pd1.checked);
				if (pd1.checked==true) {
					for (let index = 1; index <=6; index++) {
					var box=document.getElementById('b'+index)
					box.checked=true
					}
					
				}
				else{
					for(let indexx= 1; indexx <=6; indexx++) {
					var box=document.getElementById('b'+indexx)
					box.checked=false
					}
				}
				
			}
			function fu12(){
				console.log('10086');
				var sum=0
				for (let index = 1; index <= 6; index++) {
					console.log(index);
					var box=document.getElementById('b'+index)
					console.log(box.checked);
					if (box.checked==false) {
						console.log(100);
						pd1.checked=false
					}
				}
			}
			document.getElementById("selAll12").onclick=function(){
				
			}
		</script>
	</body>
</html>